﻿Public Structure LR1Transition
    Implements IEquatable(Of LR1Transition)

    Private ReadOnly m_conditionSymbol As ProductionSymbol
    Public ReadOnly Property ConditionSymbol() As ProductionSymbol
        Get
            Return m_conditionSymbol
        End Get
    End Property

    Private ReadOnly m_stackTopStateID As Integer
    Public ReadOnly Property StackTopStateID() As Integer
        Get
            Return m_stackTopStateID
        End Get
    End Property

    Private ReadOnly m_transitionID As Integer
    Public ReadOnly Property TransitionID() As Integer
        Get
            Return m_transitionID
        End Get
    End Property

    Public Sub New(ByVal stackTop As Integer, ByVal transiton As Integer, ByVal conditionSymbol As ProductionSymbol)
        Contract.AssertArgumentInRange(stackTop >= 0, "stackTop", "The stack top ID must be greater than or equal to zero")

        m_stackTopStateID = stackTop
        m_transitionID = transiton
        m_conditionSymbol = conditionSymbol
    End Sub

    Public Overloads Function Equals(ByVal other As LR1Transition) As Boolean Implements IEquatable(Of LR1Transition).Equals
        If other.ConditionSymbol.Equals(Me.ConditionSymbol) AndAlso _
            other.StackTopStateID = Me.StackTopStateID AndAlso _
            other.TransitionID = Me.TransitionID Then
            Return True
        Else
            Return False
        End If
    End Function

    Public Overrides Function Equals(ByVal obj As Object) As Boolean
        If obj Is Nothing OrElse (Not TypeOf obj Is LR1Transition) Then
            Return False
        End If

        Return Equals(CType(obj, LR1Transition))
    End Function

    Public Overrides Function GetHashCode() As Integer
        Return m_conditionSymbol.GetHashCode Xor m_stackTopStateID << 4 Xor m_transitionID << 8
    End Function
End Structure
